var data = [{
  id: 1,
  title: '111',
  number: 'AK-01',
  left: 10,
  top: 10
}, {
  id: 2,
  title: '222',
  number: 'AK-02',
  left: 120,
  top: 10
}, {
  id: 3,
  title: '333',
  number: 'AK-03',
  left: 230,
  top: 10
}];
var rightDom = document.getElementById('dragRight');
var leftLi = document.getElementsByClassName('control-drag-list');

for (var i = 0; i < leftLi.length; i++) {
  leftListDrag(leftLi[i]);
}
var DragDD = new DD({
  oBox: 'dragRight',
  data: data,
  listFn: function (domthis, data, sign) {
    console.log(domthis)
    console.log(data)
    console.log(sign)
  }
});

function leftListDrag (obj) {
  obj.onmousedown = function (event) {
    var event = event || window.event;
    var oldLeft = obj.offsetLeft;
    var oldTop = obj.offsetTop;
    var cursorLeft = event.clientX - $(obj).offset().left;
    var cursorTop = event.clientY - $(obj).offset().top;
    var curLeft = event.clientX - oldLeft;
    var curTop = event.clientY - oldTop;

    obj.style.transition = 'none';
    obj.style.zIndex = '11111';
    document.onmousemove = function (event) {
      var event = event || window.event;
      var iL = event.clientX - curLeft;
      var iT = event.clientY - curTop;

      obj.style.left = iL + "px";
      obj.style.top = iT + "px";

      return false
    }
    document.onmouseup = function (event) {
      document.onmousemove = null;
      document.onmouseup = null;
      // 右边盒子相对定位值
      var left = event.clientX - $(rightDom).offset().left - cursorLeft;
      var top = event.clientY - $(rightDom).offset().top - cursorTop;

      var l1 = $(obj).offset().left;
      var t1 = $(obj).offset().top;
      var r1 = $(obj).offset().left + obj.offsetWidth;
      var b1 = $(obj).offset().top + obj.offsetHeight;

      var l2 = $(rightDom).offset().left;
      var t2 = $(rightDom).offset().top;
      var r2 = $(rightDom).offset().left + rightDom.offsetWidth;
      var b2 = $(rightDom).offset().top + rightDom.offsetHeight;

      // 是不是在右边机床区域里
      if ((r1 > l2 && l1 < r2) && (b1 > t2 && t1 < b2)) {
        DragDD._addData(left, top);
      }
      obj.style.transition = 'all .5s';
      obj.style.left = oldLeft + "px";
      obj.style.top = oldTop + "px";
      return false;
    }
  }

}

function saveMydragdata () {
  console.log(DragDD.getData())
}